<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        a {
            text-decoration: none;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        .box {
            width: 100%;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            height: 100%;
            background: rgba(0, 0, 0, 0.4);
            position: fixed;
            display: none;
        }

        .box1 {
            width: 60%;
            height: 60%;
            margin: 50 auto;
            background: #fff;
            position: absolute;
            left: 300px;
            top: 100px;
            border-radius: 2px;
            box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
        }

        .list {
            height: 50px;
            background-color: #4491e1;
            font-size: 18px;
            line-height: 50px;
            position: relative;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            color: #fff;
        }

        #ipt {
            color: #fff;
        }
    </style>
</head>

<body>
    <input type="button" value="点击弹出窗口" id="btn" />
    <div class="box">
        <div class="box1">
            <div class="list">
                <div>标题</div>
                <a href="javascript:;" id="ipt">x</a>
            </div>
            <div>放内容</div>
        </div>
    </div>
    <script>
        // 弹出
        var box = document.querySelector(".box")
        btn.onclick = function () {
           
            box.style.display = "block"
        }
        ipt.onclick = function () {
            btn.style.display = "block";
            box.style.display = "none"
        }
        // 拖拽
        var box1 = document.querySelector(".box1")
        document.onmousedown = function (event) {
            var e = event || window.event;
            var offsetX = e.pageX - box1.offsetLeft;
            var offsetY = e.pageY - box1.offsetTop;
            document.onmousemove = function (event) {
                var d = event || window.event;
                var left1 = d.pageX - offsetX;
                var top1 = d.pageY - offsetY;
                box1.style.left = left1 + "px";
                box1.style.top = top1 + "px"
            }
            document.onmouseup = function () {
                document.onmousemove = null;
            }
        }
    </script>
</body>

</html>